// pages/paySuccessful/paySuccessful.js
const app = getApp()
var api = require('../../utils/api.js')
var util = require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderInfo: {},
    items: {},
    numbers: '',
    total_fees: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      this.setData({
        oid: options.oid
      })
    this.orderDetails()
  },

//订单详情
  orderDetails: function () {
    var that = this;
    api.POST({
      params: { oid: that.data.oid },
      url: app.globalData.base_url + 'couponsorder/info',
      success: function (res) {
        if (util.isEmpty(res.data.code)) {
          var orderInfo = res.data.data;
          var productList = orderInfo.productList;
          var numbers = 0;
          var total_fees = 0;
          for (var i = 0; i < productList.length; i++) {
            numbers = numbers / 1 + productList[i].number / 1;
            total_fees = total_fees / 1 + productList[i].total_fee / 1;
          }
          that.setData({
            orderInfo: orderInfo,
            numbers: numbers,
            total_fees: total_fees
          })
        }
      },
      fail: function (fail) {
        util.showError("网络错误");
      }
    })
  },

  // 完成
  complete: function () {
    wx.switchTab({
      url: '../index/index'
    })
  },
})